package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.MemberCoupon;
import com.xinhe.web.request.MemberCouponModel;
import com.xinhe.web.service.MemberCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(value = "会员优惠劵", tags = {"会员优惠劵"})
@RestController
@RequestMapping(value = {"/memberCoupon"}, produces = {"application/json;charset=UTF-8"})

public class MemberCouponController {
    @Autowired
    private MemberCouponService memberCouponService;

    @ApiOperation(httpMethod = "GET", value = "分页查询会员优惠劵")
    @RequestMapping({"/pageMemberCoupon"})
    public QueryResults<MemberCoupon> pageMemberCoupon(int pageNum, int pageSize) {
        return this.memberCouponService.pageMemberCoupon(pageNum,pageSize);
    }

    @ApiOperation(httpMethod = "POST", value = "保存会员优惠劵")
    @RequestMapping({"/saveMemberCoupon"})
    public Result saveMemberCoupon(@Valid MemberCouponModel model) {
        return this.memberCouponService.saveModel(model);
    }

    @ApiOperation(httpMethod = "GET", value = "删除会员优惠劵")
    @ApiImplicitParam(name = "memberCouponId", value = "标识", required = true)
    @RequestMapping({"/deleteMemberCoupon"})
    public Result deleteMemberCoupon(Long memberCouponId) {
        return this.memberCouponService.delete(memberCouponId);
    }

    @ApiOperation(httpMethod = "GET", value = "会员优惠劵详情")
    @ApiImplicitParam(name = "memberCouponId", value = "标识", required = true)
    @RequestMapping({"/detailMemberCoupon"})
    public Result detailMemberCoupon(Long memberCouponId) {
        return this.memberCouponService.findById(memberCouponId);
    }
}
